#include "include/defines.h"
#include "include/sdl/pantalla.h"
#include "include/perifericos/lectura.h"

// Handler
void handler(int);

pthread_t tid_socket;
pthread_t tid_pantalla;
pthread_t tid_lectura;

// Pantalla SDL
SDL_Surface *screen;

int main()
{
	s_mov movimiento;						// Var entre pantalla/teclado
	
	// Administrar señales
	signal(SIGINT,handler);
	
	printf("Iniciando...\n");
	
	// Levantar Socket
	/*
	 * 
	*/
	
	// Iniciar SDL
	start_sdl();
	
	// Iniciar Threads
	//pthread_create(&tid_socket, NULL, &thread_socket, (void*) NULL);
	pthread_create(&tid_pantalla, NULL, &thread_pantalla, (void*) NULL);
	pthread_create(&tid_lectura, NULL, &thread_lectura, (void*) NULL);
	
	// Espero a que terminen
	//pthread_join(tid_socket, NULL);
	pthread_join(tid_pantalla, NULL);
	pthread_join(tid_lectura, NULL);
}

void handler(int sig)
{
	pthread_exit(tid_socket);
	pthread_exit(tid_pantalla);
	pthread_exit(tid_lectura);
}
